<template>
    <view class="bottom-bar cart-bottom-bar" v-if="total.totalPrice">
        <view class="item-mian">
            <view class="price">
                <view>
                    <text>合计:</text>
                    <text class="price-text">{{ total.totalPrice }}</text>
                    <text class="price-text small">元</text>
                </view>
                <!-- <text class="item-radio" >
					{{total.totalSpace}}种
					{{total.totalNum}}件
				</text> -->
            </view>
            <text class="btn btn-success" @click="pay">提交订单</text>
        </view>
    </view>
</template>

<script>
import { mapMutations, mapState, mapGetters } from "vuex"
import { SubmitMergeOrder, submitOrderByUserCar, offlinePay, HelPayOrder } from "@/service/api/order.js"
import storage from "@/uni-sub-base/utils/storage.js"
import { getUserInfo } from "@/utils/appInit.js"
import { getSupplierCarList } from "@/utils/cartUtil.js"
import payWay from "@/components/common/pay-way.vue"
import store from "@/store/index.js"
import config from "@/config/config.js"
import orderType from "@/type/orderType.js"
export default {
    components: {
        payWay,
    },
    props: {
        total: {
            type: Object,
            default: {},
        },
        useAddress: {
            type: Object,
            default: {},
        },
        list: {
            type: Array,
            default: [],
        },
        isTempCar: {
            type: Boolean,
            default: false,
        },
        ids: {
            type: String,
            default: "",
        },
        orderType: {
            type: String,
            default: "",
        }
    },
    data() {
        return {
            balance: 0,
            payList: [],
        }
    },
    mounted() { },
    methods: {
        //点击支付
        pay() {
            if (this.checkAddress()) {
                return
            }
            this.submitOrder()
        },
        //查检收货地址
        checkAddress() {
            if (!this.useAddress || !this.useAddress.ID) {
                this.easyToast("请先选择收货地址")
                return true
            }
            return false
        },
        //提交订单
        submitOrder(payItem) {
            //检查收货地址
            if (this.checkAddress()) {
                return
            }
            let itemList = []
            this.list.forEach((e) => {
                let item = {
                    groupId: e.SupplierId,
                    remark: e.Remark || "",
                    cartList: e.productList,
                }
                itemList.push(item)
            })
            let param = {
                isTempCar: this.isTempCar,
                carIds: this.ids,
                addressId: this.useAddress.ID,
                groupType: 2,
                orderType: 12,
                itemList: itemList,
            }
            let flag = this.isTempCar && this.orderType == 4;
            let method = flag ? submitOrderByUserCar : SubmitMergeOrder;
            if (flag) {
                param.fromType = 1
                param.orderType = this.orderType
            }
            uni.showLoading({
                title: "加载中",
            })
            //提交订单接口
            method(param).then((res) => {
                if (res.State == 1) {
                    uni.hideLoading()
                    //埋点
                    let tackData = {
                        id: res.Data.ID,
                        orderPrice: res.Data.PayMoney,
                    }
                    this.tackSubmitOrder(tackData)
                    //更新购物车
                    getSupplierCarList().then((res) => { })

                    //支付
                    this.easyRemoveCurrentGoTo(
                        "/pages_supplier/packet/order/waitPayList?outTradeNo=" +
                        res.Data.OutTradeNo +
                        "&payMoney=" +
                        res.Data.PayMoney +
                        "&sn=" +
                        res.Data.Sn +
                        "&isMerge=" +
                        res.Data.IsMerge +
                        "&orderId=" +
                        res.Data.ID +
                        "&isTempCar=" + this.isTempCar,
                    )
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
    },
}
</script>

<style lang="scss">
.cart-bottom-bar {
    flex-direction: row;
    z-index: 9;

    .item-mian {
        display: flex;
        flex-direction: row;
        align-items: center;
        flex: 1;
    }

    .price {
        display: flex;
        flex: 1;
        flex-direction: column;
        align-items: flex-end;
        justify-content: flex-end;
        margin-right: 20rpx;

        .price-text {
            font-size: $font-size-36;
            font-weight: 700;
            color: $app-color-main;
            margin-left: 20rpx;
        }

        .small {
            margin-left: 6rpx;
            font-size: $font-size-24;
            margin-bottom: 6rpx;
            color: $color-gray-1;
        }

        .num {
            text {
                margin-left: 10rpx;
            }
        }
    }

    .btn {
        width: 220rpx;
        height: 80rpx;
        background: $app-color-main;
        border-radius: 45rpx;
        color: #ffffff;
        font-size: 32rpx;
    }
}
</style>
